package  systems.dla
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.geom.Point;
	import samples.BaseSample;
	import shapes.shapes2D.distribution.random.PRNG;
	import systems.dla.DLA;
	import systems.dla.DLAEmitter;
	
	/**
	 * @author Nicolas Barradeau
	 * http://en.nicoptere.net
	 */
	public class DLASample extends BaseSample 
	{
		
		public function DLASample() 
		{
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.displayState = StageDisplayState.FULL_SCREEN;
			
			sw = stage.stageWidth;
			sh = stage.stageHeight;
			
			var dla:DLA = new DLA( sw, sh );
			dla.particleSize = 5;
			dla.ipf = 2;
			
			
			var e:DLAEmitter;
			var canvas:Shape = new Shape();
			
			///*
			PRNG.seed = 0xFFF;
			var i:int = 30;
			while ( i-- )
			{
				
				canvas.graphics.beginFill( 0x0A0A0A );
				canvas.graphics.drawCircle( PRNG.random() * sw, PRNG.random() * sh, PRNG.random() * 50 );
				canvas.graphics.endFill();
				
				canvas.graphics.lineStyle( 2, 0xDDDDDD );
				var p0:Point;
				var p1:Point;
				p0 = new Point( PRNG.random() * sw, PRNG.random() * sh );
				p1 = new Point( PRNG.random() * sw, PRNG.random() * sh );
				//canvas.graphics.moveTo( p0.x, p0.y );
				//canvas.graphics.lineTo( p1.x, p1.y );
				
				p0 = new Point( PRNG.random() * sw, PRNG.random() * sh );
				p1 = new Point( PRNG.random() * sw, PRNG.random() * sh );
				
				e = DLAEmitter.pointEmitter( p0 );
				//e = DLAEmitter.lineEmitter( p0, p1 );
				
				e.emissionMode = DLAEmitter._OUTSIDE;
				DLA.register( e );
				
			}
			//canvas.graphics.drawRect( 0, 0, sw, sh );
			canvas.graphics.drawRect( sw * .5 - 250, sh * .5 - 250, 500, 500 );
			
			//e = DLAEmitter.pointEmitter( new Point( 250, 250 ) );
			//DLA.register( e );
			//e = DLAEmitter.pointEmitter( new Point( 550, 450 ) );
			//DLA.register( e );
			//e = DLAEmitter.pointEmitter( new Point( 550, 200 ) );
			//DLA.register( e );
			
			//*/
			
			
			/*
			e = DLAEmitter.lineEmitter( new Point( sw / 2-300, sh / 2 +200 ), new Point(sw / 2 +300, sh / 2 +200 ) );
			e.speed = 2;
			e.emissionMode = DLAEmitter._OUTSIDE;
			DLA.register( e );
			canvas.graphics.lineStyle( 10, 0x333333 );
			canvas.graphics.drawRect( 20, 20, sw - 20, sh - 20 );
			canvas.graphics.moveTo(  sw / 2 - 300, sh / 2 - 200 );
			canvas.graphics.lineTo(  sw / 2 + 300, sh / 2 - 200 );
			
			canvas.graphics.drawCircle( sw / 2, sh / 2, 25 );
			
			//*/
			
			
			/*
			e = DLAEmitter.discEmitter( new Point( sw / 2, sh / 2), 150 );
			e.speed = 2.5;
			e.emissionMode = DLAEmitter._BOTH;
			DLA.register( e );
			
			canvas.graphics.beginFill( 0x333333 );
			canvas.graphics.drawCircle( sw * .5, sh * .5, 50 );
			canvas.graphics.endFill();
			
			canvas.graphics.lineStyle( 10, 0x333333 );
			canvas.graphics.drawRect( sw * .5 - 250, sh * .5 - 250, 500, 500 );
			//*/
			
			
			
			
			
			
			dla.bitmapData.draw( canvas );
			addChild( dla );
			dla.start();
			
			
		} 
		
	}

}